package com.groupseven.happycampus.controller;

import com.groupseven.happycampus.common.pojo.Fixture;
import com.groupseven.happycampus.common.result.LayuiPageVo;
import com.groupseven.happycampus.common.result.R;
import com.groupseven.happycampus.service.FixtureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/fixture")
public class FixtureController {

    @Autowired
    private FixtureService fixtureService;


    /**
     *  模糊查询及分页查询赛程信息
     * @param params
     * @return
     */
    @RequestMapping("/selectFixture")
    public LayuiPageVo<Fixture> selectFixture(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return fixtureService.selectFixture(params);
    }



    /**
     * 添加赛程信息
     * @param fixture
     * @return
     */

    @RequestMapping("/addFixture")
    public R addFixture(Fixture fixture) {
        System.out.println(fixture);
        int result = fixtureService.addFixture(fixture);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }



    /**
     * 根据赛程编号(id)删除赛程信息
     * @param id
     * @return
     */
    @GetMapping("/deleteFixtureById")
    public R deleteFixtureById(Integer id){
        int result = fixtureService.deleteFixtureById(id);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }



    /**
     * 根据赛程编号(ids)批量删除赛程信息信息
     * @param ids
     * @return
     */
    @GetMapping("/deleteFixtureByIds")
    public R deleteFixtureByIds(String ids){
        //根据Id删除学生信息
        int result = fixtureService.deleteFixtureByIds(ids);
        if(result>0){
            return R.ok();
        }else{
            return R.error();
        }
    }


    /**
     * 修改赛程信息
     * @param fixture
     * @return
     */

    @RequestMapping("/updateFixture")
    public R updateFixture(Fixture fixture){
        System.out.println(fixture);
        int result = fixtureService.updateFixture(fixture);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }
}
